import Vue from 'vue'
import VueRouter from 'vue-router'
import vue from "../main"

Vue.use(VueRouter)

//引入组件
// const Login = () => import("../pages/Login.vue")
// const Layout = () => import("../pages/Layout")
// const Home = () => import("../pages/Home.vue")
// const noteFound = () => import("../pages/404.vue")
// const userManger = () => import("../pages/userManger/userManger.vue")
// const Personalinformation = () => import("../pages/Personalinformation/Personaliinfo.vue")
// const RoleManger = () => import("../pages/RoleManger/RoleManger.vue")
// const MenuManger = () => import("../pages/MenuManger/MenuManger.vue")
// const DeptManger = () => import("../pages/DeptManger/DeptManger.vue")
// const DictManger = () => import("../pages/DictManger/DictManger.vue")
// const Logger = () => import("../pages/Logger.vue")

//路由映射规则
const routes = [{
        path: "/",
        redirect: "/login"
    },
    {
        name: "login",
        path: "/login",
        component: () => import("../pages/Login.vue"),
        meta: {
            title: "员工培训管理系统平台",
            requireLogin: false
        }
    },
    {
        name: "main",
        path: "/main",
        component: () => import("../pages/Layout"),
        children: [{
                path: "",
                redirect: "home"
            },
            {
                name: 'home',
                path: 'home',
                component:()=>import("../pages/Home.vue"),
                meta: {
                    title: "首页",

                }
            },
            {
                name: 'logger',
                path: 'logger',
                component: () => import("../pages/Logger.vue"),
                meta: {
                    title: "日志管理",

                }
            },
            {
                name: '用户管理',
                path: '/main/user-manage',
                component: () => import("../pages/userManger/userManger.vue"),
                meta: {
                    title: "用户管理",

                }
            },
            {
                name: '个人信息',
                path: 'ain-info',
                component: () => import("../pages/Personalinformation/Personaliinfo.vue"),
                meta: {
                    title: "个人信息",

                }
            },
            {
                name: '角色管理',
                path: 'role-manage',
                component: () => import("../pages/RoleManger/RoleManger.vue"),
                meta: {
                    title: "角色管理",

                }
            },
            {
                name: '菜单管理',
                path: 'menu-manage',
                component: () => import("../pages/MenuManger/MenuManger.vue"),
                meta: {
                    title: "菜单管理",

                }
            },
            {
                name: '部门管理',
                path: 'dept-manage',
                component: () => import("../pages/DeptManger/DeptManger.vue"),
                meta: {
                    title: "部门管理",

                }
            },
            {
                name: '班级管理',
                path: 'class-manage',
                component: () => import("../pages/ClassManger/ClassManger.vue"),
                meta: {
                    title: "班级管理",

                }
            },
            {
                name: '字典管理',
                path: 'dict-manage',
                component: () => import("../pages/DictManger/DictManger.vue"),
                meta: {
                    title: "字典管理",

                }
            },
            {
                name: '员工分数管理',
                path: 'employee-score-management',
                component: () => import("../pages/EmpGradeManger/EmpGradeManger.vue"),
                meta: {
                    title: "员工分数管理",

                }
            },
            {
                name: '课程信息查看反馈',
                path: 'course-look-feedback',
                component: () => import("../pages/CourseFeedback/CourseFeedback.vue"),
                meta: {
                    title: "课程信息查看反馈",

                }
            },
            {
                name: '课程信息管理',
                path: 'train-course-manage',
                component: () => import("../pages/TrainCourseManage/TrainCourseManage.vue"),
                meta: {
                    title: "课程信息查看反馈",

                }
            },
            {
                name: '通知公告发布管理',
                path: 'notice-manage',
                component: () => import("../pages/NoticeManage/noticeManage.vue"),
                meta: {
                    title: "通知公告发布管理",

                }
            },
            {
                name: '公告发布页面',
                path: 'notice-submit',
                component: () => import("../pages/NoticeManage/notice.vue"),
                meta: {
                    title: "公告发布页面",

                }
            },
            {
                name: 'update-notice',
                path: 'update-notice',
                component: () => import("../pages/NoticeManage/updateNotice.vue"),
                meta: {
                    title: "公告修改页面",

                }
            },
            {
                name: 'see-notice',
                path: 'see-notice',
                component: () => import("../pages/NoticeManage/seeNotice.vue"),
                meta: {
                    title: "员工公告查看页面",

                }
            },
            {
                name: 'view-announcement',
                path: 'view-announcement',
                component: () => import("../pages/NoticeManage/tseeNotice.vue"),
                meta: {
                    title: "教员公告查看页面",

                }
            },
            {
                name: "404",
                path: "404",
                component: () => import("../pages/404.vue"),
        
            },
            {path: '*', redirect: '404'}

        ]


    },
  
]
const router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {

    if (to.meta.requireLogin) {
        // 验证用户是否登录
        let userInfo = localStorage.getItem("token")
        if (!userInfo) {
            vue.$notify.error("您尚未登录，或登录信息已过期，请重新登录")
            // console.log(vm)
            return next("/login")
        }



        // 验证用户是否有权限访问此路径:to.path
        // let menus = userInfo.menus_url.map(item=>{
        //     return '/main'+item
        // })


        // menus.push("/main/home")



        // if (menus.indexOf(to.path) < 0) {
        //     vue.$notify.warning("您没有权限访问该路径，请联系管理员")
        //     return next("/main/home")
        // }
    }
    next()
    document.title = to.meta.title
})


export default router